﻿using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections;
using System.Text;

namespace suirui.ZhuMu.Model
{
    public class TokenDTO
    {
        public string Username { get; set; }

        public string Password { get; set; }

        public DateTime Time { get; set; }
    }

    public class APIResult
    {
        public APIResult()
        {
            Code = ErrorCode.Success;
            Message = "接口调用成功！";
        }
        /// <summary>
        ///状态码
        /// </summary>
        public int Code { get; set; }
        /// <summary>
        ///简单描述
        /// </summary>
        public string Message { get; set; }

        public string TraceId { get; set; }
        public override string ToString()
        {
            return $"Code:{Code},Message:{Message},TraceId:{TraceId}";
        }
    }

    /// <summary>
    /// 增删改时返回的参数
    /// </summary>
    public class APIResult<T> : APIResult
    {
        public T Data { get; set; } 
        /// <summary>
        /// 附加的备注信息
        /// </summary>
        public string Remark { get; set; }

        public override string ToString()
        {
            StringBuilder dataStr = new StringBuilder();
            if (Data is IList)
            {
                var listData = Data as IList;
                foreach (var item in listData)
                {
                    dataStr.Append(item.ToString());
                    dataStr.Append(",");
                }
            }
            else
            {
                dataStr.Append(Data?.ToString());
            }
            return $"Code:{Code},Message:{Message},TraceId:{TraceId},Data:{dataStr}";
        }
    }

    public class LoginResult<T> : APIResult<T>
    {
        /// <summary>
        /// 访问接口的Token
        /// </summary>
        public string AccessToken { get; set; }
        /// <summary>
        /// 刷新token
        /// </summary>
        public string RefreshToken { get; set; }
    }


        public enum PublicErrorCode
    {
        /// <summary>
        /// 参数错误
        /// </summary>
        ParamInvlid = 100,

        /// <summary>
        /// 数据处理错误
        /// </summary>
        DataOperFail = 110,

        /// <summary>
        /// 数据不存在
        /// </summary>
        DataNotExist = 111,

        /// <summary>
        /// 数据已经存在
        /// </summary>
        DataAlreadyExist = 112,

        /// <summary>
        /// Token无效
        /// </summary>
        TokenInvlid = 113,

        /// <summary>
        /// 目的API不存在
        /// </summary>
        ApiNotExist = 121,

        /// <summary>
        /// 无权限
        /// </summary>
        NoPermission = 130,

        /// <summary>
        /// 成功
        /// </summary>
        Success = 200,

        /// <summary>
        /// 内部错误
        /// </summary>
        InnerError = 301,

        /// <summary>
        /// 禁止访问
        /// </summary>
        Forbidden = 403,

        /// <summary>
        /// zhumuAPI调用失败
        /// </summary>
        ZhumuApiInvokeFail = 800,

        /// <summary>
        /// 日程API调用失败
        /// </summary>
        CalendarApiInvokeFail = 801,

        /// <summary>
        /// 阿里云调用失败
        /// </summary>
        UploadAliyunFail = 802,

        /// <summary>
        /// 错误次数太多
        /// </summary>
        TooManyFailedAttempts = 501,

        /// <summary>
        /// 验证失败
        /// </summary>
        CheckCodeError = 502,

        /// <summary>
        /// 用户无权限
        /// </summary>
        ViewerNoPermission = 503,

        /// <summary>
        /// 认证方式变化
        /// </summary>
        AuthTypeChanged = 504,

        /// <summary>
        /// 非法昵称
        /// </summary>
        IllegallyName = 505,

        /// <summary>
        /// 验证码错误
        /// </summary>
        PictureCodeError = 506,

        /// <summary>
        /// 获取短信验证码次数过多
        /// </summary>
        TooManyGetMeesageCode = 507,

        /// <summary>
        /// 更新失败
        /// </summary>
        UpdateFail = 508,

        /// <summary>
        /// 删除失败
        /// </summary>
        DeleteFail = 509,
        /// <summary>
        /// 未知错误
        /// </summary>
        Unknown = 900,
    }
}
